package com.igeek.d0614.test1;

import java.util.HashMap;

/**
 * @Author: zhiyu
 * @Date:17:35
 * @DESC:
 */
public class SingletonTest {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            final int temp = i;
            Thread thread = new Thread(() -> {
                Singleton.method();
                Singleton singleton = Singleton.getInstance();
                singleton.name = "小" + temp;
                map.put(singleton.name, singleton.hashCode());
//                System.out.println("singleton.hashCode() = " + singleton.hashCode());
            }, "线程" + i);
            thread.start();
            try {
                thread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        for (String s: map.keySet()) {
            System.out.println("singleton.name = " +s+" hashcode="+map.get(s));
        }
        System.out.println(Singleton.getInstance().name);
    }
}
